# coding=utf-8
# timeaxis_light_Tool
# Arnold  render tool for maya 2018
# author :deliang  #E-mail :524707056@qq.com
# TurBo?????

import sys, os, re
import maya.cmds as cmd
import maya.mel as mm
import maya.mel as mel
import pymel.core as pm
import mtoa.aovs as aovs

from PySide2 import QtCore, QtWidgets

class NameWindow(QtWidgets.QWidget):
    """
    重命名hip文件
    """
    name_Signal = QtCore.Signal(str)

    def __init__(self):
        super(NameWindow, self).__init__()
        self.main_layout = QtWidgets.QVBoxLayout()
        self.name_label = QtWidgets.QLabel('New Name:')
        self.name_edit = QtWidgets.QLineEdit()
        self.name_btn = QtWidgets.QPushButton('OK')
        self.name_btn.clicked.connect(self._set_name)
        self.main_layout.addWidget(self.name_label)
        self.main_layout.addWidget(self.name_edit)
        self.main_layout.addWidget(self.name_btn)
        self.setLayout(self.main_layout)

    def _set_name(self):
        name = self.name_edit.text()
        if name:
            self.name_Signal.emit(name)
            self.close()


globIsoFlag = []

WINDOW_NAME = 'Tool'


def maya_main_window():
    import maya.OpenMayaUI as apiUI
    from shiboken2 import wrapInstance
    main_win_ptr = apiUI.MQtUtil.mainWindow()
    return wrapInstance(long(main_win_ptr), QtWidgets.QWidget)


class Dialog(QtWidgets.QDialog):

    def __init__(self, parent=None, show=True):
        super(Dialog, self).__init__(parent=parent)
        self.mainLayout=QtWidgets.QHBoxLayout()
        #self.setMih(1500)
        self.LeftLayout = QtWidgets.QVBoxLayout()
        self.rightLayout = QtWidgets.QVBoxLayout()#QGridLayout#
        self.CopyTransformBox()
        self.IsoBox()
        self.maskGroup()
        self.workSpace()
        self.setAOVGroup()
        self.setAOVGroup2()
        self.physXskyGrp()
        self.openSkyFile()
        self.openFileBox()
        self.MotionVectorGro()
        self.creatLayerGro()
        self.createShader()
        self.creatShadowGro()
        self.optMayaGrp()
        self.renderwindowgru()
        self.setSubGro()
        self.attributesGroup()
        self.Fast_Sample_Set()

        self.LeftLayout.addWidget(self.CopyTransformGBox)#, 0, 0, 1, 2)

        self.LeftLayout.addWidget(self.IsoGBox)#, 1, 0, 1, 2)

        self.LeftLayout.addWidget(self.workSpaceGroup)#, 2, 0, 1, 1)
        self.LeftLayout.addWidget(self.aovGoup)#, 2, 1, 1, 1)
        self.LeftLayout.addWidget(self.aovGoupset)#, 3, 0, 1, 1)
        self.LeftLayout.addWidget(self.physkyGoup)#, 3, 1, 1, 1)

        self.LeftLayout.addWidget(self.layerGroup)#, 4, 0, 1, 2)

        self.LeftLayout.addWidget(self.shaderLayerGroup)#, 5, 0, 1, 2)

        self.LeftLayout.addWidget(self.maskGroup)#, 6, 0, 1, 2)
        # self.LeftLayout.addWidget(self.CopyTransformGBox, 0, 0, 1, 2)
        #
        # self.LeftLayout.addWidget(self.IsoGBox, 1, 0, 1, 2)
        #
        # self.LeftLayout.addWidget(self.workSpaceGroup, 2, 0, 1, 1)
        # self.LeftLayout.addWidget(self.aovGoup, 2, 1, 1, 1)
        # self.LeftLayout.addWidget(self.aovGoupset, 3, 0, 1, 1)
        # self.LeftLayout.addWidget(self.physkyGoup, 3, 1, 1, 1)
        #
        # self.LeftLayout.addWidget(self.layerGroup, 4, 0, 1, 2)
        #
        # self.LeftLayout.addWidget(self.shaderLayerGroup, 5, 0, 1, 2)
        #
        # self.LeftLayout.addWidget(self.maskGroup, 6, 0, 1, 2)

        # self.LeftLayout.addWidget(self.MotionVectorGroup, 7, 0, 1, 2)
        #
        # self.LeftLayout.addWidget(self.shdowlayerGroup, 8, 0, 1, 2)
        #
        # self.LeftLayout.addWidget(self.subGroup, 9, 0, 1, 2)
        #
        # self.LeftLayout.addWidget(self.attributes_Set, 11, 0, 1, 2)
        # self.LeftLayout.addWidget(self.Fast_Sample_Set, 12, 0, 1, 2)
        #
        # self.LeftLayout.addWidget(self.openskyPath, 13, 0, 1, 1)
        # self.LeftLayout.addWidget(self.openFPath, 14, 1, 1, 1)
        #
        # self.LeftLayout.addWidget(self.optGroup, 15, 0, 1, 1)
        # self.LeftLayout.addWidget(self.displayRenderWinGro, 16, 1, 1, 1)

        self.rightLayout.addWidget(self.MotionVectorGroup)#, 0, 0, 1, 2)

        self.rightLayout.addWidget(self.shdowlayerGroup)#, 1, 0, 1, 2)

        self.rightLayout.addWidget(self.subGroup)#, 2, 0, 1, 2)

        self.rightLayout.addWidget(self.attributes_Set)#, 3, 0, 1, 2)
        self.rightLayout.addWidget(self.Fast_Sample_Set)#, 4, 0, 1, 2)

        self.rightLayout.addWidget(self.openskyPath)#, 5, 0, 1, 1)
        self.rightLayout.addWidget(self.openFPath)#, 6, 1, 1, 1)

        self.rightLayout.addWidget(self.optGroup)#, 7, 0, 1, 1)
        self.rightLayout.addWidget(self.displayRenderWinGro)#, 8, 1, 1, 1)

        self.mainLayout.addLayout(self.LeftLayout)
        self.mainLayout.addLayout(self.rightLayout)
        self.setLayout(self.mainLayout)

        if show:
            self.show()

    ####################################################################################
    #############################  Attributes Contol    #################################
    ####################################################################################

    def attributesGroup(self):
        self.attributes_Set = QtWidgets.QGroupBox("Attributes Control")

        self.casts_shadows_checkbox = QtWidgets.QCheckBox('Casts shadows')
        self.casts_shadows_checkbox.setCheckState(QtCore.Qt.Checked)
        self.casts_shadows_checkbox.stateChanged.connect(self._attr_cast)
        self.receive_shadows_checkbox = QtWidgets.QCheckBox('Receive shadows')
        self.receive_shadows_checkbox.setCheckState(QtCore.Qt.Checked)
        self.receive_shadows_checkbox.stateChanged.connect(self._attr_receive)
        self.primary_visbility_checkbox   = QtWidgets.QCheckBox('Primary Visbility')
        self.primary_visbility_checkbox.setCheckState(QtCore.Qt.Checked)
        self.primary_visbility_checkbox.stateChanged.connect(self._attr_visibily)
        self.ai_matte_checkbox = QtWidgets.QCheckBox('Ai Matte')
        self.ai_matte_checkbox.setCheckState(QtCore.Qt.Unchecked)
        self.ai_matte_checkbox.stateChanged.connect(self._attr_aiMatte)

        attribute_layout = QtWidgets.QGridLayout()
        attribute_layout.addWidget(self.casts_shadows_checkbox, 0, 0, 1, 1)
        attribute_layout.addWidget(self.receive_shadows_checkbox, 0, 1, 1, 1)
        attribute_layout.addWidget(self.primary_visbility_checkbox, 1, 0, 1, 1)
        attribute_layout.addWidget(self.ai_matte_checkbox, 1, 1, 1, 1)

        self.attributes_Set.setLayout(attribute_layout)


    def _attr_cast(self,status):
        objs = cmd.ls(sl=1, dag=1, s=1)
        if objs:
            if status==QtCore.Qt.Checked:
                for i in objs:
                    cmd.setAttr(i + '.castsShadows', 1)
            else:
                for i in objs:
                    cmd.setAttr(i + '.castsShadows', 0)

    def _attr_receive(self,status):
        objs = cmd.ls(sl=1, dag=1, s=1)
        if objs:
            if status==QtCore.Qt.Checked:
                for i in objs:
                    cmd.setAttr(i + '.receiveShadows', 1)
            else:
                for i in objs:
                    cmd.setAttr(i + '.receiveShadows', 0)

    def _attr_visibily(self,status):
        objs = cmd.ls(sl=1, dag=1, s=1)
        if objs:
            if status==QtCore.Qt.Checked:
                for i in objs:
                    cmd.setAttr(i + '.primaryVisibility', 1)
            else:
                for i in objs:
                    cmd.setAttr(i + '.primaryVisibility', 0)

    def _attr_aiMatte(self,status):
        objs = cmd.ls(sl=1, dag=1, s=1)
        if objs:
            if status==QtCore.Qt.Checked:
                for i in objs:
                    try:
                        cmd.editRenderLayerAdjustment(i + '.aiMatte')
                    except Exception as _attr_aiMatte_ERR:
                        pass
                    cmd.setAttr(i + '.aiMatte', 1)
            else:
                for i in objs:
                    try:
                        cmd.editRenderLayerAdjustment(i + '.aiMatte')
                    except Exception as _attr_aiMatte_ERR:
                        pass
                    cmd.setAttr(i + '.aiMatte', 0)


    ####################################################################################
    #############################   Fast Sample Set    #################################
    ####################################################################################

    def Fast_Sample_Set(self):
        self.Fast_Sample_Set = QtWidgets.QGroupBox("Fast_Setting")

        self.AA_4_Render_Sample = QtWidgets.QPushButton('AA_4_Render_Sample')
        self.Mask_Sample = QtWidgets.QPushButton('Mask_Sample')
        self.AA_3_Render_Sample = QtWidgets.QPushButton('AA_3_Render_Sample')
        self.clampintensity = QtWidgets.QPushButton('Clamping intensity')

        Fast_Sample_Set = QtWidgets.QGridLayout()
        Fast_Sample_Set.addWidget(self.AA_4_Render_Sample, 0, 0, 1, 1)
        Fast_Sample_Set.addWidget(self.Mask_Sample, 0, 1, 1, 1)
        Fast_Sample_Set.addWidget(self.AA_3_Render_Sample, 1, 0, 1, 1)
        Fast_Sample_Set.addWidget(self.clampintensity, 1, 1, 1, 1)

        self.Fast_Sample_Set.setLayout(Fast_Sample_Set)

        self.connect(self.AA_4_Render_Sample, QtCore.SIGNAL('clicked()'), self.AA_4)
        self.connect(self.Mask_Sample, QtCore.SIGNAL('clicked()'), self.msksmp)
        self.connect(self.AA_3_Render_Sample, QtCore.SIGNAL('clicked()'), self.AA_3)
        self.connect(self.clampintensity, QtCore.SIGNAL('clicked()'), self.clamp)

    def AA_4(self):
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 4)
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.aovMode", 1)

    def msksmp(self):
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.AASamples")
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 2)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIDiffuseSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISpecularSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GITransmissionSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISssSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIVolumeSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.aovMode")
        cmd.setAttr("defaultArnoldRenderOptions.aovMode", 0)

    def AA_3(self):
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 3)
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 3)
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.aovMode", 1)

    def clamp(self):
        cmd.setAttr("defaultArnoldRenderOptions.use_sample_clamp", 1)
        cmd.setAttr("defaultArnoldRenderOptions.use_sample_clamp_AOVs", 1)
        cmd.setAttr("defaultArnoldRenderOptions.AASampleClamp", 1)
        cmd.setAttr("defaultArnoldRenderOptions.indirectSampleClamp", 1)

    ####################################################################################
    #####################        copy transform         ################################
    ####################################################################################

    def CopyTransformBox(self):

        self.CopyTransformGBox = QtWidgets.QGroupBox("COPY  TRANSFORM")
        self.allTr = QtWidgets.QPushButton('ALL')
        self.Tr_translate = QtWidgets.QPushButton('Translate')
        self.Tr_rotate = QtWidgets.QPushButton('Rotate')

        CopyTransformLayout = QtWidgets.QGridLayout()
        CopyTransformLayout.addWidget(self.allTr, 2, 0, 1, 1)
        CopyTransformLayout.addWidget(self.Tr_translate, 2, 1, 1, 1)
        CopyTransformLayout.addWidget(self.Tr_rotate, 2, 2, 1, 1)
        self.CopyTransformGBox.setLayout(CopyTransformLayout)

        self.connect(self.allTr, QtCore.SIGNAL('clicked()'), self.copyall)
        self.connect(self.Tr_translate, QtCore.SIGNAL('clicked()'), self.copytraslate)
        self.connect(self.Tr_rotate, QtCore.SIGNAL('clicked()'), self.Rotate)

    def copyall(self):
        print
        1
        dlight = cmd.ls(sl=True, tr=True)
        for i in range(1, len(dlight)):
            cmd.copyAttr(dlight[0], dlight[i], values=True, attribute=['translate', 'rotate'])

    def copytraslate(self):
        dlight = cmd.ls(sl=True, tr=True)
        for i in range(1, len(dlight)):
            cmd.copyAttr(dlight[0], dlight[i], values=True, attribute=['translate'])

    def Rotate(self):
        dlight = cmd.ls(sl=True, tr=True)
        for i in range(1, len(dlight)):
            cmd.copyAttr(dlight[0], dlight[i], values=True, attribute=['rotate'])
        ####################################################################################

    #####################        Isolate Light  Tool       #############################
    ####################################################################################
    def IsoBox(self):

        self.IsoGBox = QtWidgets.QGroupBox("Isolate Light  Tool")

        self.isolate = QtWidgets.QPushButton('Isolate Selection')
        self.lookthrought = QtWidgets.QPushButton('Look Throught')
        self.clean = QtWidgets.QPushButton('clean')

        IsoLayout = QtWidgets.QGridLayout()
        IsoLayout.addWidget(self.isolate, 2, 0, 1, 1)
        IsoLayout.addWidget(self.lookthrought, 2, 1, 1, 1)
        IsoLayout.addWidget(self.clean, 2, 2, 1, 1)
        self.IsoGBox.setLayout(IsoLayout)

        self.connect(self.isolate, QtCore.SIGNAL('clicked()'), self.isoLightSel)
        self.connect(self.lookthrought, QtCore.SIGNAL('clicked()'), self.lookThu)
        self.connect(self.clean, QtCore.SIGNAL('clicked()'), self.lookThuClean)

    def isoLightSel(self, *args):
        global globIsoFlag
        allLights = getAllLights()
        lightSel = getSelectedLights()
        resultSel = []
        for each in allLights:
            if not each in lightSel:
                resultSel.append(each)
        if not globIsoFlag:
            self.isolate.setStyleSheet("QPushButton:hover{color:red}")
            print
            'Modo Isolate Light = ON'
            for each in resultSel:
                cmd.setAttr(each + '.v', 0)
            globIsoFlag = 1
        else:
            pass
            self.isolate.setStyleSheet("QPushButton:hover{color:0.38,0.38,0.38}")
            print
            'Modo Isolate Light = OFF'
            for each in allLights:
                cmd.setAttr(each + '.v', 1)
            globIsoFlag = 0

    def lookThu(self, *args):
        global previousCamera
        panel = pm.playblast(activeEditor=True)
        panel_name = str(panel).split('|')[-1]
        objs = pm.ls(sl=True)
        if objs:
            previousCamera = pm.windows.modelPanel(panel_name, query=True, camera=True)
            cmd = 'lookThroughModelPanelClipped %s %s 1 100000000' % (objs[0], panel_name)
            mm.eval(cmd)

    def lookThuClean(self, *args):
        global previousCamera
        panel = pm.playblast(activeEditor=True)
        panel_name = str(panel).split('|')[-1]
        if previousCamera:
            pm.windows.modelPanel(panel_name, e=1, camera=previousCamera)

        self.clean_camera_under_cam()

    def clean_camera_under_cam(self):
        ltypes = ['ambientLight', 'directionalLight', 'pointLight', 'spotLight', 'areaLight', 'volumeLight',
                  'aiAreaLight', 'aiSkyDomeLight', 'aiPhotometricLight']
        cam_list = list()
        for ltype in ltypes:
            for cam in pm.ls(type=ltype):
                t = cam.listRelatives(p=1)[0]
                ccs = [c for c in t.listRelatives(c=1) if pm.objectType(c) == 'camera']
                if ccs:
                    cam_list.extend(ccs)
        for cam in cam_list:
            try:
                pm.delete(cam)
            except:
                pass
            ####################################################################################

    #####################        open SKY           #############################
    ####################################################################################
    def openSkyFile(self):

        self.openskyPath = QtWidgets.QGroupBox("Sky Path")

        self.openskybnt = QtWidgets.QPushButton('Open Sky Path')

        skyLayout = QtWidgets.QGridLayout()
        skyLayout.addWidget(self.openskybnt, 2, 0, 1, 1)

        self.openskyPath.setLayout(skyLayout)

        self.connect(self.openskybnt, QtCore.SIGNAL('clicked()'), self.openSkyPath)

    def openSkyPath(self):
        os.startfile(str("\\\\192.168.1.248\cgteamwork3\HDRI_map"))

    ####################################################################################
    #####################        open pic path             #############################
    ####################################################################################

    def openFileBox(self):

        self.openFPath = QtWidgets.QGroupBox("Images Files")

        self.openFileBox = QtWidgets.QPushButton('Open Scenes images Path')

        openLayout = QtWidgets.QGridLayout()
        openLayout.addWidget(self.openFileBox, 2, 0, 1, 1)

        self.openFPath.setLayout(openLayout)

        self.connect(self.openFileBox, QtCore.SIGNAL('clicked()'), self.openPath)

    def openPath(self):

        if os.path.exists(str(cmd.workspace(fn=True) + '/images')):
            os.startfile(str(cmd.workspace(fn=True) + '/images'))
        else:
            os.startfile(str(cmd.workspace(fn=True)))

    ####################################################################################
    #####################        Set AOV                  #############################
    ####################################################################################
    ##aov22222222222222222##

    def setAOVGroup2(self):
        self.aovGoupset = QtWidgets.QGroupBox("AOV_Set")

        self.reduceaovbtn = QtWidgets.QPushButton('Reduce AOV')
        self.luxuryaovbtn = QtWidgets.QPushButton('Luxury AOV')

        aovLayout2 = QtWidgets.QGridLayout()
        aovLayout2.addWidget(self.reduceaovbtn, 0, 0, 1, 1)
        aovLayout2.addWidget(self.luxuryaovbtn, 0, 1, 1, 1)

        self.aovGoupset.setLayout(aovLayout2)

        self.connect(self.reduceaovbtn, QtCore.SIGNAL('clicked()'), self.reduceAov)
        self.connect(self.luxuryaovbtn, QtCore.SIGNAL('clicked()'), self.luxuryAov)

    def reduceAov(self):
        cmd.setAttr("aiAOV_emission.enabled", 0)
        cmd.setAttr("aiAOV_opacity.enabled", 0)
        cmd.setAttr("aiAOV_sss.enabled", 0)
        cmd.setAttr("aiAOV_transmission.enabled", 0)

    def luxuryAov(self):
        cmd.setAttr("aiAOV_emission.enabled", 1)
        cmd.setAttr("aiAOV_opacity.enabled", 1)
        cmd.setAttr("aiAOV_sss.enabled", 1)
        cmd.setAttr("aiAOV_transmission.enabled", 1)

    ##aov11111111111111111##
    def setAOVGroup(self):
        self.aovGoup = QtWidgets.QGroupBox("AOV")

        self.aov = QtWidgets.QPushButton('Deploy AOV')

        aovLayout = QtWidgets.QGridLayout()
        aovLayout.addWidget(self.aov, 2, 0, 1, 1)

        self.aovGoup.setLayout(aovLayout)

        self.connect(self.aov, QtCore.SIGNAL('clicked()'), self.makeAOV)

    def aovExists(self,avo_name):
        #origin_aovs=[u'aiAOV_Mblur', u'aiAOV_N', u'aiAOV_Normal', u'aiAOV_OCC', u'aiAOV_P', u'aiAOV_Point', u'aiAOV_RGBA', u'aiAOV_Rim', u'aiAOV_UV', u'aiAOV_WF', u'aiAOV_Z', u'aiAOV_Z_Depth', u'aiAOV_coat', u'aiAOV_crypto_asset', u'aiAOV_crypto_material', u'aiAOV_crypto_object', u'aiAOV_diffuse', u'aiAOV_diffuse_albedo', u'aiAOV_emission', u'aiAOV_motionvector', u'aiAOV_opacity', u'aiAOV_specular', u'aiAOV_specular_direct', u'aiAOV_specular_indirect', u'aiAOV_sss', u'aiAOV_transmission']
        origin_aovs=aovs.AOVInterface().getAOVNodes()
        if 'aiAOV_'+avo_name in origin_aovs:
            return True
        else:
            return False

    def makeAOV(self):
        cmd.setAttr("defaultArnoldDriver.mergeAOVs", 1)

        # Mblur#
        if not self.aovExists('Mblur'):
            timeaxis_aov_Mblur = aovs.AOVInterface().addAOV('Mblur', aovType='rgba')
            timeaxis_aov_aiMotionVector = cmd.createNode('aiMotionVector', name='timeaxis_aov_aiMotionVector')
            cmd.setAttr(timeaxis_aov_aiMotionVector + '.raw', 1)
            timeaxis_aov_aiVectorMap = cmd.createNode('aiVectorMap', name='timeaxis_aov_aiVectorMap')
            cmd.setAttr(timeaxis_aov_aiVectorMap + '.tangentSpace', 0)
            cmd.setAttr(timeaxis_aov_aiVectorMap + '.order', 2)
            cmd.connectAttr(timeaxis_aov_aiMotionVector + '.outColor', timeaxis_aov_aiVectorMap + '.input')
            cmd.connectAttr(timeaxis_aov_aiVectorMap + '.outValue', timeaxis_aov_Mblur.node + ".defaultValue")
            cmd.setAttr(timeaxis_aov_Mblur.node + ".enabled", 0)
        # Mblur#

        # Nonmal#
        if not self.aovExists('Normal'):
            timeaxis_aov_Nonmal = aovs.AOVInterface().addAOV('Normal', aovType='rgba')
            timeaxis_aov_N_samplerInfo = cmd.createNode('samplerInfo', name='timeaxis_aov_N_samplerInfo')
            timeaxis_aov_N_aiUtility = cmd.createNode('aiUtility', name='timeaxis_aov_N_aiUtility')
            cmd.setAttr(timeaxis_aov_N_aiUtility + '.shadeMode', 2)
            cmd.connectAttr(timeaxis_aov_N_samplerInfo + '.normalCamera', timeaxis_aov_N_aiUtility + '.color')
            cmd.connectAttr(timeaxis_aov_N_aiUtility + '.outColor', timeaxis_aov_Nonmal.node + ".defaultValue")
        # Nonmal#

        # Point#
        if not self.aovExists('Point'):
            timeaxis_aov_Point = aovs.AOVInterface().addAOV('Point', aovType='rgba')
            timeaxis_aov_P_samplerInfo = cmd.createNode('samplerInfo', name='timeaxis_aov_P_samplerInfo')
            timeaxis_aov_P_aiUtility = cmd.createNode('aiUtility', name='timeaxis_aov_P_aiUtility')
            cmd.setAttr(timeaxis_aov_P_aiUtility + '.shadeMode', 2)
            cmd.connectAttr(timeaxis_aov_P_samplerInfo + '.pointCamera', timeaxis_aov_P_aiUtility + '.color')
            cmd.connectAttr(timeaxis_aov_P_aiUtility + '.outColor', timeaxis_aov_Point.node + ".defaultValue")
            cmd.setAttr("aiAOV_Point.enabled", 0)
        # Point#

        # OCC#
        if not self.aovExists('OCC'):
            timeaxis_aov_OCC = aovs.AOVInterface().addAOV('OCC', aovType='rgba')
            timeaxis_aov_occ_aiAO = cmd.createNode('aiAmbientOcclusion', name='timeaxis_aov_occ_aiAO')
            cmd.connectAttr(timeaxis_aov_occ_aiAO + '.outColor', timeaxis_aov_OCC.node + '.defaultValue')
        # OCC#

        # Rim#
        if not self.aovExists('Rim'):
            timeaxis_aov_rim = aovs.AOVInterface().addAOV('Rim', aovType='rgba')
            timeaxis_aov_rim_ramp = cmd.createNode('ramp', name='timeaxis_aov_rim_ramp')
            cmd.setAttr(timeaxis_aov_rim_ramp + ".colorEntryList[1].color", 1, 1, 1)
            cmd.setAttr(timeaxis_aov_rim_ramp + ".colorEntryList[0].color", 0, 0, 0)
            cmd.setAttr(timeaxis_aov_rim_ramp + ".colorEntryList[0].position", 0.5)
            timeaxis_aov_rim_samplerInfo = cmd.createNode('samplerInfo', name='timeaxis_aov_rim_samplerInfo')
            cmd.connectAttr(timeaxis_aov_rim_samplerInfo + '.facingRatio', timeaxis_aov_rim_ramp + '.uvCoord.vCoord')
            timeaxis_aov_rim_aiUtility = cmd.createNode('aiUtility', name='timeaxis_aov_rim_aiUtility')
            cmd.setAttr(timeaxis_aov_rim_aiUtility + '.shadeMode', 1)
            cmd.connectAttr(timeaxis_aov_rim_ramp + '.outColor', timeaxis_aov_rim_aiUtility + '.color')
            cmd.connectAttr(timeaxis_aov_rim_aiUtility + '.outColor', timeaxis_aov_rim.node + ".defaultValue")
            cmd.setAttr(timeaxis_aov_rim.node + ".enabled", 0)
        # Rim#

        # Z_Depth#
        if not self.aovExists('Z_Depth'):
            timeaxis_aov_Z_Depth = aovs.AOVInterface().addAOV('Z_Depth', aovType='rgba')
            timeaxis_aov_z_samplerInfo = cmd.createNode('samplerInfo', name='timeaxis_aov_z_samplerInfo')
            timeaxis_aov_Z_multiplyDivide = cmd.createNode('multiplyDivide', name='timeaxis_aov_Z_multiplyDivide')
            cmd.setAttr(timeaxis_aov_Z_multiplyDivide + ".input2X", -1.1)
            timeaxis_aov_Z_setRange = cmd.createNode('setRange', name='timeaxis_aov_Z_setRange')
            cmd.setAttr(timeaxis_aov_Z_setRange + ".minX", 1)
            cmd.setAttr(timeaxis_aov_Z_setRange + ".oldMinX", 0.1)
            cmd.setAttr(timeaxis_aov_Z_setRange + ".oldMaxX", 1500)
            timeaxis_aov_Z_aiUtility = cmd.createNode('aiUtility', name='timeaxis_aov_Z_aiUtility')
            cmd.setAttr(timeaxis_aov_Z_aiUtility + '.shadeMode', 2)
            cmd.connectAttr(timeaxis_aov_z_samplerInfo + '.pointCamera.pointCameraZ',
                            timeaxis_aov_Z_multiplyDivide + '.input1.input1X')
            cmd.connectAttr(timeaxis_aov_Z_multiplyDivide + '.input1.input1X', timeaxis_aov_Z_setRange + '.value.valueX')
            cmd.connectAttr(timeaxis_aov_Z_setRange + '.outValueX', timeaxis_aov_Z_aiUtility + '.color.colorR')
            cmd.connectAttr(timeaxis_aov_Z_setRange + '.outValueX', timeaxis_aov_Z_aiUtility + '.color.colorG')
            cmd.connectAttr(timeaxis_aov_Z_setRange + '.outValueX', timeaxis_aov_Z_aiUtility + '.color.colorB')
            cmd.connectAttr(timeaxis_aov_Z_aiUtility + '.outColor', timeaxis_aov_Z_Depth.node + ".defaultValue")
            cmd.setAttr("aiAOV_Z_Depth.enabled", 1)
        # Z_Depth#

        # WF#
        if not self.aovExists('WF'):
            timeaxis_aov_WF = aovs.AOVInterface().addAOV('WF', aovType='rgba')
            timeaxis_aov_WF_aiWF = cmd.createNode('aiWireframe', name='timeaxis_aov_WF_aiWF')
            cmd.setAttr(timeaxis_aov_WF_aiWF + '.edgeType', 1)
            cmd.setAttr(timeaxis_aov_WF_aiWF + '.lineWidth', 0.5)
            cmd.setAttr(timeaxis_aov_WF_aiWF + '.lineWidth', 0.5)
            cmd.setAttr(timeaxis_aov_WF_aiWF + ".fillColor", 0, 0, 0)
            cmd.setAttr(timeaxis_aov_WF_aiWF + ".lineColor", 1, 1, 1)
            cmd.connectAttr(timeaxis_aov_WF_aiWF + '.outColor', timeaxis_aov_WF.node + '.defaultValue')
            cmd.setAttr(timeaxis_aov_WF.node + ".enabled", 0)
        # WF#

        # other_aov&set#
        if not self.aovExists('RGBA'):
            aovs.AOVInterface().addAOV('RGBA', aovType='rgba')
            cmd.setAttr("aiAOV_RGBA.lightGroups", 1)
        if not self.aovExists('diffuse'):
            aovs.AOVInterface().addAOV('diffuse', aovType='rgb')
        if not self.aovExists('specular'):
            aovs.AOVInterface().addAOV('specular', aovType='rgb')
        if not self.aovExists('coat'):
            aovs.AOVInterface().addAOV('coat', aovType='rgb')
            cmd.setAttr("aiAOV_coat.enabled", 0)
        if not self.aovExists('sss'):
            aovs.AOVInterface().addAOV('sss', aovType='rgb')
        if not self.aovExists('diffuse_albedo'):
            aovs.AOVInterface().addAOV('diffuse_albedo', aovType='rgb')
        if not self.aovExists('emission'):
            aovs.AOVInterface().addAOV('emission', aovType='rgb')
        if not self.aovExists('opacity'):
            aovs.AOVInterface().addAOV('opacity', aovType='rgb')
        if not self.aovExists('transmission'):
            aovs.AOVInterface().addAOV('transmission', aovType='rgb')
        if not self.aovExists('Z'):
            aovs.AOVInterface().addAOV('Z', aovType='float')
            cmd.setAttr("aiAOV_Z.enabled", 0)

        if not self.aovExists('N'):
            aovs.AOVInterface().addAOV('N', aovType='vector')
            cmd.setAttr("aiAOV_N.enabled", 0)
        if not self.aovExists('P'):
            aovs.AOVInterface().addAOV('P', aovType='vector')
        if not self.aovExists('motionvector'):
            aovs.AOVInterface().addAOV('motionvector')

        if not self.aovExists('specular_direct'):
            aovs.AOVInterface().addAOV('specular_direct')
            cmd.setAttr("aiAOV_specular_direct.enabled", 0)
        if not self.aovExists('specular_indirect'):
            aovs.AOVInterface().addAOV('specular_indirect')
            cmd.setAttr("aiAOV_specular_indirect.enabled", 0)

        # crypto#
        try:
            if not self.aovExists('crypto_asset'):
                crypto_asset_aov = aovs.AOVInterface().addAOV('crypto_asset', aovType='rgb')
            if not self.aovExists('crypto_material'):
                crypto_material_aov = aovs.AOVInterface().addAOV('crypto_material', aovType='rgb')
            if not self.aovExists('crypto_object'):
                crypto_object_aov = aovs.AOVInterface().addAOV('crypto_object', aovType='rgb')
            if not self.aovExists('cryptomatte'):
                cryptomatte_node = cmd.createNode('cryptomatte', name='cryptomatte_node')
                cmd.connectAttr(cryptomatte_node + '.outColor', crypto_asset_aov.node + '.defaultValue')
                cmd.connectAttr(cryptomatte_node + '.outColor', crypto_material_aov.node + '.defaultValue')
                cmd.connectAttr(cryptomatte_node + '.outColor', crypto_object_aov.node + '.defaultValue')
        except Exception as crypto_ERR:
            print(str(crypto_ERR))
        # crypto#

        # UV#
        if not self.aovExists('UV'):
            timeaxis_aov_UV = aovs.AOVInterface().addAOV('UV', aovType='rgba')
            timeaxis_aov_UV_aiUT = cmd.createNode('aiUtility', name='timeaxis_aov_UV_aiUT')
            cmd.setAttr(timeaxis_aov_UV_aiUT + ".shadeMode", 2)
            cmd.setAttr(timeaxis_aov_UV_aiUT + ".colorMode", 5)
            cmd.connectAttr(timeaxis_aov_UV_aiUT + '.outColor', timeaxis_aov_UV.node + '.defaultValue')
            cmd.setAttr("aiAOV_UV.enabled", 0)
        # UV#

        self.setDeafult()

    def setDeafult(self):
        sceneAOVs = aovs.AOVInterface().getAOVNodes(names=True)
        for i in sceneAOVs:
            if i[0] == 'motionvector':
                cmd.setAttr(i[1] + ".enabled", 0)
            else:
                pass

    #####################################################################################
    #############################  fast physXskydome   ##################################
    #####################################################################################

    def physXskyGrp(self):

        self.physkyGoup = QtWidgets.QGroupBox("Fast PhySky")

        self.physkybtn = QtWidgets.QPushButton('PhySky')

        skybtnLayout = QtWidgets.QGridLayout()
        skybtnLayout.addWidget(self.physkybtn, 0, 2, 1, 1)

        self.physkyGoup.setLayout(skybtnLayout)

        self.connect(self.physkybtn, QtCore.SIGNAL('clicked()'), self.CreatPhysXskydome)

    def CreatPhysXskydome(self):
        timeaxis_SkyDome = cmd.createNode('aiSkyDomeLight', name='timeaxis_SkyDome')
        cmd.setAttr(timeaxis_SkyDome + '.aiSamples', 3)
        cmd.setAttr(timeaxis_SkyDome + '.camera', 0)
        cmd.setAttr(timeaxis_SkyDome + '.transmission', 0)
        cmd.setAttr(timeaxis_SkyDome + '.aiAov', "lgt_env", type="string")

        timeaxis_aiPhysicalSky = cmd.createNode('aiPhysicalSky', name='timeaxis_aiPhysicalSky')
        cmd.setAttr(timeaxis_aiPhysicalSky + '.turbidity', 8)
        cmd.setAttr(timeaxis_aiPhysicalSky + '.elevation', 90)
        cmd.setAttr(timeaxis_aiPhysicalSky + '.intensity', 2)
        cmd.setAttr(timeaxis_aiPhysicalSky + '.enableSun', 0)

        cmd.connectAttr(timeaxis_aiPhysicalSky + '.outColor', timeaxis_SkyDome + '.color')

    ####################################################################################
    #####################              mask                    #########################
    ####################################################################################

    def maskGroup(self):

        self.maskGroup = QtWidgets.QGroupBox("Mask Layer")

        self.maskSpbtn = QtWidgets.QPushButton('Create Mask Layer To Selection')
        self.maskRedbtn = QtWidgets.QPushButton('Red')
        self.maskRedbtn.setStyleSheet("background-color: rgb(255, 0, 0)")

        self.maskGreenbtn = QtWidgets.QPushButton('Green')
        self.maskGreenbtn.setStyleSheet("background-color: rgb(0, 255, 0)")

        self.maskBluebtn = QtWidgets.QPushButton('Blue')
        self.maskBluebtn.setStyleSheet("background-color: rgb(0, 0, 255)")

        self.maskBlackbtn = QtWidgets.QPushButton('Alpha')
        self.maskBlackbtn.setStyleSheet("background-color: rgb(0, 0, 0)")

        maskbtnLayout = QtWidgets.QGridLayout()
        maskbtnLayout.addWidget(self.maskSpbtn, 0, 0, 1, 4)
        maskbtnLayout.addWidget(self.maskRedbtn, 1, 0, 1, 1)
        maskbtnLayout.addWidget(self.maskGreenbtn, 1, 1, 1, 1)
        maskbtnLayout.addWidget(self.maskBluebtn, 1, 2, 1, 1)
        maskbtnLayout.addWidget(self.maskBlackbtn, 1, 3, 1, 1)

        self.maskGroup.setLayout(maskbtnLayout)

        self.connect(self.maskSpbtn, QtCore.SIGNAL('clicked()'), self.makeMaskeLayerFn)
        self.connect(self.maskRedbtn, QtCore.SIGNAL('clicked()'), self.mRedFn)
        self.connect(self.maskGreenbtn, QtCore.SIGNAL('clicked()'), self.mGreenFn)
        self.connect(self.maskBluebtn, QtCore.SIGNAL('clicked()'), self.mBlueFn)
        self.connect(self.maskBlackbtn, QtCore.SIGNAL('clicked()'), self.mBlackFn)

    def makeMaskeLayerFn(self):
        if not self.layerExist('Mask'):
            cmd.createRenderLayer(name="Mask", mc=True, nr=True)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.AASamples")
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 2)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIDiffuseSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISpecularSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GITransmissionSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISssSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIVolumeSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 0)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.aovMode")
        cmd.setAttr("defaultArnoldRenderOptions.aovMode", 0)

    def mRedFn(self):
        obj = []
        obj = cmd.ls(sl=1, dag=1, s=1)
        if "Red_mask_SG_tm" in cmd.ls(set=1):
            cmd.hyperShade(assign="Red_mask_SG_tm")
        else:
            Red_mask_tm = cmd.shadingNode('surfaceShader', name='Red_mask_tm_shder', asShader=1)
            cmd.setAttr(Red_mask_tm + ".outColor", 1, 0, 0, type="double3")
            cmd.setAttr(Red_mask_tm + ".outMatteOpacity", 0, 0, 0, type="double3")

            #cmd.hyperShade(assign=Red_mask_tm)
            Red_mask_SG_tm = cmd.sets(renderable=1, empty=1, name='Red_mask_SG_tm')
            cmd.connectAttr(Red_mask_tm + '.outColor', Red_mask_SG_tm + '.surfaceShader', f=1)
            cmd.sets(obj, e=1, forceElement=Red_mask_SG_tm)

    def mGreenFn(self):
        obj = []
        obj = cmd.ls(sl=1, dag=1, s=1)
        # self.obj = cmd.ls(sl=1,dag=1,s=1)
        if "Green_mask_SG_tm" in cmd.ls(set=1):
            cmd.hyperShade(assign="Green_mask_SG_tm")
        else:
            Green_mask_tm = cmd.shadingNode('surfaceShader', name='Green_mask_tm_shder', asShader=1)
            cmd.setAttr(Green_mask_tm + ".outColor", 0, 1, 0, type="double3")
            cmd.setAttr(Green_mask_tm + ".outMatteOpacity", 0, 0, 0, type="double3")

            #cmd.hyperShade(assign=Green_mask_tm)
            Green_mask_SG_tm = cmd.sets(renderable=1, empty=1, name='Green_mask_SG_tm')
            cmd.connectAttr(Green_mask_tm + '.outColor', Green_mask_SG_tm + '.surfaceShader', f=1)
            cmd.sets(obj, e=1, forceElement=Green_mask_SG_tm)

    def mBlueFn(self):
        obj = []
        obj = cmd.ls(sl=1, dag=1, s=1)
        if "Blue_mask_SG_tm" in cmd.ls(set=1):
            cmd.hyperShade(assign="Blue_mask_SG_tm")
        else:
            Blue_mask_tm = cmd.shadingNode('surfaceShader', name='Blue_mask_tm_shder', asShader=1)
            cmd.setAttr(Blue_mask_tm + ".outColor", 0, 0, 1, type="double3")
            cmd.setAttr(Blue_mask_tm + ".outMatteOpacity", 0, 0, 0, type="double3")

            #cmd.hyperShade(assign=Blue_mask_tm)
            Blue_mask_SG_tm = cmd.sets(renderable=1, empty=1, name='Blue_mask_SG_tm')
            cmd.connectAttr(Blue_mask_tm + '.outColor', Blue_mask_SG_tm + '.surfaceShader', f=1)
            cmd.sets(obj, e=1, forceElement=Blue_mask_SG_tm)

    def mBlackFn(self):
        obj = []
        obj = cmd.ls(sl=1, dag=1, s=1)
        if "Black_mask_SG_tm" in cmd.ls(set=1):
            cmd.hyperShade(assign="Black_mask_SG_tm")
        else:
            Black_mask_tm = cmd.shadingNode('surfaceShader', name='Black_mask_tm_shder', asShader=1)
            cmd.setAttr(Black_mask_tm + ".outColor", 0, 0, 0, type="double3")

            #cmd.hyperShade(assign=Black_mask_tm)
            Black_mask_SG_tm = cmd.sets(renderable=1, empty=1, name='Black_mask_SG_tm')
            cmd.connectAttr(Black_mask_tm + '.outColor', Black_mask_SG_tm + '.surfaceShader', f=1)
            cmd.sets(obj, e=1, forceElement=Black_mask_SG_tm)

    ####################################################################################
    #####################            optimized         #############################
    ####################################################################################

    def optMayaGrp(self):
        self.optGroup = QtWidgets.QGroupBox("")

        self.optbtn = QtWidgets.QPushButton('Optimize')
        self.nameSpcabtn = QtWidgets.QPushButton('Clear Name Space')

        optLayout = QtWidgets.QGridLayout()
        optLayout.addWidget(self.optbtn, 0, 0, 1, 1)
        optLayout.addWidget(self.nameSpcabtn, 0, 1, 1, 1)

        self.optGroup.setLayout(optLayout)

        self.connect(self.optbtn, QtCore.SIGNAL('clicked()'), self.doOptFn)
        self.connect(self.nameSpcabtn, QtCore.SIGNAL('clicked()'), self.nameSpcaeFn)

    def doOptFn(self):
        # pm.mel.source('cleanUpScene')

        # pm.mel.scOpt_performOneCleanup({
        # 'setsOption',
        # 'nurbsSrfOption',
        # 'partitionOption',
        # 'animationCurveOption',
        # 'deformerOption',
        # 'unusedSkinInfsOption',
        # 'brushOption',
        # 'shaderOption',
        # 'unknownNodes',
        # 'shadingNetworksOption'
        # }
        # )
        # unknown = pm.ls(type="unknown")
        # unknown = pm.filter(lambda node: not node.isReferenced(), unknown)
        # for node in unknown:
        # if not pm.objExists(node):
        # continue
        # pm.delete(node)

        pm.delete(pm.ls(type="unknown"))
        pm.mel.eval("MLdeleteUnused;")
        print
        "Optimize "

    def nameSpcaeFn(self):
        allNodes = pm.ls()

        for node in allNodes:

            buffer = node.name()
            try:
                newName = buffer.split(':')[-1]
                pm.rename(node, newName)
            except:
                pass

    ####################################################################################
    #####################        set workspace             #############################
    ####################################################################################
    def workSpace(self):

        self.workSpaceGroup = QtWidgets.QGroupBox("Work Space")

        self.workSpbtn = QtWidgets.QPushButton('Arnold Work Space')

        spbtnLayout = QtWidgets.QGridLayout()
        spbtnLayout.addWidget(self.workSpbtn, 2, 1, 1, 1)

        self.workSpaceGroup.setLayout(spbtnLayout)

        self.connect(self.workSpbtn, QtCore.SIGNAL('clicked()'), self.setArWorkSp)

    def setArWorkSp(self):
        if not cmd.pluginInfo('mtoa', l=1, q=1):
            cmd.loadPlugin('mtoa')
            print
            'arnold ???????????????????????2??????????????????'

        if cmd.getAttr('defaultRenderGlobals.currentRenderer') != 'arnold':

            cmd.setAttr('defaultRenderGlobals.currentRenderer', l=False)
            cmd.setAttr('defaultRenderGlobals.currentRenderer', 'arnold', type='string')
            self.ArSet()
        else:
            self.ArSet()

    def ArSet(self):
        try:
            self.options = pm.PyNode('defaultArnoldRenderOptions')
        except:
            self.options = pm.createNode('aiOptions', name='defaultArnoldRenderOptions', skipSelect=True, shared=True)
        try:

            self.filterNode = pm.PyNode('defaultArnoldFilter')

        except:

            self.filterNode = pm.createNode('aiAOVFilter', name='defaultArnoldFilter', skipSelect=True, shared=True)
        try:
            self.driverNode = pm.PyNode('defaultArnoldDriver')
        except:
            self.driverNode = pm.createNode('aiAOVDriver', name='defaultArnoldDriver', skipSelect=True, shared=True)
        try:

            self.resolution = pm.PyNode('defaultResolution')
        except:
            self.resolution = pm.createNode('resolution', name='defaultResolution', skipSelect=True, shared=True)

        cmd.setAttr('defaultRenderGlobals.imageFilePrefix', "<Scene>/<RenderLayer>/<RenderLayer>", type="string")
        pm.mel.setMayaSoftwareFrameExt(7, 0)

        cmd.colorManagementPrefs(e=True, cmEnabled=True)

        # Common_Tab#
        cmd.setAttr("defaultArnoldDriver.halfPrecision", 1)
        cmd.setAttr("defaultArnoldDriver.exrTiled", 1)
        cmd.setAttr("defaultArnoldDriver.autocrop", 0)
        cmd.setAttr("defaultArnoldDriver.append", 0)
        cmd.setAttr("defaultArnoldDriver.mergeAOVs", 1)

        cmd.setAttr("defaultRenderGlobals.extensionPadding", 4)
        cmd.setAttr("defaultRenderGlobals.startFrame", 1)

        cmd.setAttr("defaultResolution.aspectLock", 0)

        # Arnold Renderer_Tab#
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 2)
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 2)

        cmd.setAttr("defaultArnoldRenderOptions.enableProgressiveRender", 1)

        ###### lock sampling pattern ######
        cmd.setAttr("defaultArnoldRenderOptions.lock_sampling_noise", 1)

        ###### Textures ######
        cmd.setAttr("defaultArnoldRenderOptions.use_existing_tiled_textures", 1)
        cmd.setAttr("defaultArnoldRenderOptions.autotx", 0)

        ##### Other Setting #####
        cmd.setAttr("defaultArnoldRenderOptions.bucketSize", 32)
        cmd.setAttr("defaultArnoldRenderOptions.bucketScanning", 2)
        cmd.setAttr("defaultArnoldRenderOptions.abortOnError", 0)
        cmd.setAttr("defaultArnoldRenderOptions.log_max_warnings", 100)
        cmd.setAttr("defaultArnoldRenderOptions.log_to_console", 0)
        cmd.setAttr("defaultArnoldDriver.mergeAOVs", 1)
        cmd.setAttr("defaultArnoldRenderOptions.range_type", 1)
        cmd.setAttr("defaultArnoldRenderOptions.motion_blur_enable", 0)

        ##### Cam_persp_view_Repair #####
        cmd.setAttr("perspShape.nearClipPlane", 1)
        cmd.setAttr("perspShape.farClipPlane", 1000000000)

        ##### Render_Cam_view_Repair #####
        camls = cmd.ls(cameras=1)
        for i in camls:
            if cmd.getAttr(i + ".renderable") == 1:
                cmd.setAttr(i + ".nearClipPlane", 0.01)
                cmd.setAttr(i + ".farClipPlane", 1000000000)

        ###### #Camera_Motion_blur ######

    ###    """
    #        camls = cmd.ls(cameras=1)

    #        for i in camls:
    #             if cmd.getAttr(i+ ".renderable")==1:
    #                cmd.setAttr(i+ ".aiUseGlobalShutter", 0)
    #                cmd.setAttr(i+ ".aiShutterStart", 0.5)
    #                cmd.setAttr(i+ ".aiShutterEnd", 0.5)

    ###    """
    ##############################################################
    ####################################################################################
    #####################        set MotionVectorGro             #############################
    ####################################################################################
    def MotionVectorGro(self):

        self.MotionVectorGroup = QtWidgets.QGroupBox("Motion Blur")

        self.EnabledMotionVectorbtn = QtWidgets.QPushButton('Enabled Motion Vector Layer')
        self.DisabledMotionVectorbtn = QtWidgets.QPushButton('Disabled Motion Vector Layer')
        self.EnabledMotionBlurbtn = QtWidgets.QPushButton('Enabled Render Motion Blur')
        self.DisabledMotionBlurbtn = QtWidgets.QPushButton('Disabled Render Motion Blur')
        self.creatMVlayerbtn = QtWidgets.QPushButton('Create MV Layer To Select')
        self.setMVshaderbtn = QtWidgets.QPushButton('Assign MV Shader To Select')

        MotionVectorbtnLayout = QtWidgets.QGridLayout()

        MotionVectorbtnLayout.addWidget(self.EnabledMotionVectorbtn, 1, 0, 1, 1)
        MotionVectorbtnLayout.addWidget(self.DisabledMotionVectorbtn, 1, 1, 1, 1)
        MotionVectorbtnLayout.addWidget(self.EnabledMotionBlurbtn, 2, 0, 1, 1)
        MotionVectorbtnLayout.addWidget(self.DisabledMotionBlurbtn, 2, 1, 1, 1)
        MotionVectorbtnLayout.addWidget(self.creatMVlayerbtn, 3, 0, 1, 1)
        MotionVectorbtnLayout.addWidget(self.setMVshaderbtn, 3, 1, 1, 1)

        self.MotionVectorGroup.setLayout(MotionVectorbtnLayout)

        self.connect(self.EnabledMotionVectorbtn, QtCore.SIGNAL('clicked()'), self.EnabledMotionVector)
        self.connect(self.DisabledMotionVectorbtn, QtCore.SIGNAL('clicked()'), self.DisabledMotionVector)
        self.connect(self.EnabledMotionBlurbtn, QtCore.SIGNAL('clicked()'), self.EnabledMotionBlur)
        self.connect(self.DisabledMotionBlurbtn, QtCore.SIGNAL('clicked()'), self.DisabledMotionBlur)
        self.connect(self.creatMVlayerbtn, QtCore.SIGNAL('clicked()'), self.creatMVlayer)
        self.connect(self.setMVshaderbtn, QtCore.SIGNAL('clicked()'), self.setMVshader)

    def EnabledMotionVector(self):

        cmd.setAttr("defaultArnoldRenderOptions.motion_blur_enable", 1)
        cmd.setAttr("defaultArnoldRenderOptions.motion_steps", 3)
        cmd.setAttr("defaultArnoldRenderOptions.range_type", 1)

        camls = cmd.ls(cameras=1)
        for i in camls:
            if cmd.getAttr(i + ".renderable") == 1:
                cmd.setAttr(i + ".aiUseGlobalShutter", 0)
                cmd.setAttr(i + ".aiShutterStart", 0.5)
                cmd.setAttr(i + ".aiShutterEnd", 0.5)

        cmd.setAttr("aiAOV_motionvector.enabled", 1)
        cmd.setAttr("aiAOV_Mblur.enabled", 1)
        cmd.setAttr("defaultArnoldRenderOptions.range_type", 1)

    def DisabledMotionVector(self):

        cmd.setAttr("defaultArnoldRenderOptions.motion_blur_enable", 0)
        cmd.setAttr("defaultArnoldRenderOptions.motion_steps", 2)
        cmd.setAttr("defaultArnoldRenderOptions.range_type", 1)

        camls = cmd.ls(cameras=1)
        for i in camls:
            if cmd.getAttr(i + ".renderable") == 1:
                cmd.setAttr(i + ".aiUseGlobalShutter", 1)
                cmd.setAttr(i + ".aiShutterStart", 0)
                cmd.setAttr(i + ".aiShutterEnd", 1)

        cmd.setAttr("aiAOV_motionvector.enabled", 0)
        cmd.setAttr("aiAOV_Mblur.enabled", 0)

    def EnabledMotionBlur(self):

        cmd.setAttr("defaultArnoldRenderOptions.motion_blur_enable", 1)
        cmd.setAttr("defaultArnoldRenderOptions.motion_steps", 3)
        cmd.setAttr("defaultArnoldRenderOptions.range_type", 1)

        camls = cmd.ls(cameras=1)
        for i in camls:
            if cmd.getAttr(i + ".renderable") == 1:
                cmd.setAttr(i + ".aiUseGlobalShutter", 1)
                cmd.setAttr(i + ".aiShutterStart", 0)
                cmd.setAttr(i + ".aiShutterEnd", 1)

        cmd.setAttr("aiAOV_motionvector.enabled", 0)
        cmd.setAttr("aiAOV_Mblur.enabled", 0)

    def DisabledMotionBlur(self):

        cmd.setAttr("defaultArnoldRenderOptions.motion_blur_enable", 0)
        cmd.setAttr("defaultArnoldRenderOptions.motion_steps", 2)
        cmd.setAttr("defaultArnoldRenderOptions.range_type", 1)

        camls = cmd.ls(cameras=1)
        for i in camls:
            if cmd.getAttr(i + ".renderable") == 1:
                cmd.setAttr(i + ".aiUseGlobalShutter", 1)
                cmd.setAttr(i + ".aiShutterStart", 0)
                cmd.setAttr(i + ".aiShutterEnd", 1)

        cmd.setAttr("aiAOV_motionvector.enabled", 0)
        cmd.setAttr("aiAOV_Mblur.enabled", 0)

    def layerExist(self,layerName):
        layers=[i for i in cmd.ls(type='renderLayer')]
        if layerName in layers:
            return True
        else:
            return False

    def creatMVlayer(self):
        self.sl_mobj = cmd.ls(sl=True, dag=True, s=True)
        if not self.layerExist("Motion_Vector"):
            cmd.createRenderLayer(name="Motion_Vector", mc=True, nr=True)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.AASamples")
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 3)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIDiffuseSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISpecularSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GITransmissionSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISssSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIVolumeSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.motion_blur_enable")
        cmd.setAttr("defaultArnoldRenderOptions.motion_blur_enable", 1)
        cmd.setAttr("defaultArnoldRenderOptions.range_type", 1)
        cmd.editRenderLayerAdjustment("aiAOV_RGBA.lightGroups")
        cmd.setAttr("aiAOV_RGBA.lightGroups", 0)

        sceneAOVs = aovs.AOVInterface().getAOVNodes(names=True)

        for i in sceneAOVs:

            if i[0] != 'motionvector':
                cmd.editRenderLayerAdjustment(i[1] + ".enabled")
                cmd.setAttr(i[1] + ".enabled", 0)

            else:
                cmd.editRenderLayerAdjustment(i[1] + ".enabled")
                cmd.setAttr(i[1] + ".enabled", 1)

        cmd.setAttr("aiAOV_Mblur.enabled", 1)

    def setMVshader(self):
        timeaxis_aov_MV_aiMotionVector = cmd.createNode('aiMotionVector', name='timeaxis_aov_MV_aiMotionVector')
        self.timeaxis_aov_MV_aiUitility = cmd.createNode('aiUtility', name='timeaxis_aov_MV_aiUitility')
        cmd.setAttr(self.timeaxis_aov_MV_aiUitility + ".shadeMode", 2)
        cmd.setAttr(timeaxis_aov_MV_aiMotionVector + ".maxDisplace", 0.5)
        cmd.setAttr(timeaxis_aov_MV_aiMotionVector + ".raw", 1)
        cmd.connectAttr(timeaxis_aov_MV_aiMotionVector + '.outColor', self.timeaxis_aov_MV_aiUitility + '.color')

        cmd.select(self.sl_mobj)
        cmd.hyperShade(assign=self.timeaxis_aov_MV_aiUitility)  # ????????????????????
        newMVSg = cmd.sets(renderable=1, empty=1, name='mvSG')
        # newMVSg= cmd.createNode ('shadingEngine',name='timeaxis_aov_MV_aiUitilitySG')
        # cmd.connectAttr(disNode+'.out',newSg+'.displacementShader',f=1) # ???????? ????????2????????????
        cmd.connectAttr(self.timeaxis_aov_MV_aiUitility + '.outColor', newMVSg + '.surfaceShader', f=1)
        cmd.sets(self.sl_mobj, e=1, forceElement=newMVSg)

    ####################################################################################
    #####################        creat layer               #############################
    ####################################################################################
    def creatLayerGro(self):

        self.layerGroup = QtWidgets.QGroupBox("Creat Layer")

        self.envLayerbtn = QtWidgets.QPushButton('ENV Layer')
        self.chaLayerbtn = QtWidgets.QPushButton('Cha Layer')
        self.envSpeLayerbtn=QtWidgets.QPushButton('Env_spe Layer')
        self.chaAoLayerbtn = QtWidgets.QPushButton('Cha_ao Layer')

        layerbtnLayout = QtWidgets.QGridLayout()

        layerbtnLayout.addWidget(self.envLayerbtn, 2, 0, 1, 1)
        layerbtnLayout.addWidget(self.chaLayerbtn, 2, 1, 1, 1)
        layerbtnLayout.addWidget(self.envSpeLayerbtn, 3, 0, 2, 1)
        layerbtnLayout.addWidget(self.chaAoLayerbtn, 3, 1, 2, 1)

        self.layerGroup.setLayout(layerbtnLayout)

        self.connect(self.envLayerbtn, QtCore.SIGNAL('clicked()'), self.creatENV)
        self.connect(self.chaLayerbtn, QtCore.SIGNAL('clicked()'), self.creatCha)
        self.connect(self.envSpeLayerbtn, QtCore.SIGNAL('clicked()'), self.creatEnvSpe)
        self.connect(self.chaAoLayerbtn, QtCore.SIGNAL('clicked()'), self.creatChaAo)

    def creatENV(self):
        cmd.createRenderLayer(name="env_10", mc=True, nr=True)


    def creatCha(self):
        cmd.createRenderLayer(name="Cha_10", mc=True, nr=True)


    def creatEnvSpe(self):
        if not self.layerExist('Env_spe'):
            cmd.createRenderLayer(name="Env_spe", mc=True, nr=True)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.AASamples", layer='Env_spe')
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 3)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIDiffuseSamples", layer='Env_spe')
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISpecularSamples", layer='Env_spe')
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 3)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GITransmissionSamples", layer='Env_spe')
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISssSamples", layer='Env_spe')
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIVolumeSamples", layer='Env_spe')
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.aovMode", layer='Env_spe')
        cmd.setAttr("defaultArnoldRenderOptions.aovMode", 1)
        cmd.editRenderLayerAdjustment("aiAOV_specular_direct.enabled", layer='Env_spe')
        cmd.setAttr("aiAOV_specular_direct.enabled", 1)
        cmd.editRenderLayerAdjustment("aiAOV_specular_indirect.enabled", layer='Env_spe')
        cmd.setAttr("aiAOV_specular_indirect.enabled", 1)
        cmd.editRenderLayerAdjustment("aiAOV_RGBA.lightGroups")
        cmd.setAttr("aiAOV_RGBA.lightGroups", 0)

        sceneAOVs = aovs.AOVInterface().getAOVNodes(names=True)
        for i in sceneAOVs:
            if i[0] != 'specular_direct':
                cmd.editRenderLayerAdjustment(i[1] + ".enabled")
                cmd.setAttr(i[1] + ".enabled", 0)
            else:
                cmd.editRenderLayerAdjustment(i[1] + ".enabled")
                cmd.setAttr(i[1] + ".enabled", 1)
        #cmd.setAttr("aiAOV_Mblur.enabled", 1)

    def creatChaAo(self):
        if not self.layerExist('Cha_ao'):
            cmd.createRenderLayer(name="Cha_ao", mc=True, nr=True)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.AASamples", layer='Cha_ao')
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 3)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIDiffuseSamples", layer='Cha_ao')
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISpecularSamples", layer='Cha_ao')
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 3)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GITransmissionSamples", layer='Cha_ao')
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISssSamples", layer='Cha_ao')
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIVolumeSamples", layer='Cha_ao')
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.aovMode", layer='Cha_ao')
        cmd.setAttr("defaultArnoldRenderOptions.aovMode", 0)


    ####################################################################################
    #####################           Creat  Shader         #############################
    ####################################################################################
    def createShader(self):
        self.shaderLayerGroup = QtWidgets.QGroupBox("Shader Layer")
        self.surfaceShaderbtn = QtWidgets.QPushButton('Create SurfaceShader To Select')
        self.aoShaderbtn = QtWidgets.QPushButton('Create aiAmbientOcclusion To Select')

        shaderlayerbtnLayout = QtWidgets.QGridLayout()

        shaderlayerbtnLayout.addWidget(self.surfaceShaderbtn, 2, 0, 1, 1)
        shaderlayerbtnLayout.addWidget(self.aoShaderbtn, 2, 1, 1, 1)

        self.shaderLayerGroup.setLayout(shaderlayerbtnLayout)

        self.connect(self.surfaceShaderbtn, QtCore.SIGNAL('clicked()'), self.createStandSurfaceShader)
        self.connect(self.aoShaderbtn, QtCore.SIGNAL('clicked()'), self.createAOShader)

    def createStandSurfaceShader(self):
        self.name_win=NameWindow()
        self.name_win.name_Signal.connect(self._create_aiStandardSurface_shader)
        self.name_win.show()

    def createAOShader(self):
        self.name_win=NameWindow()
        self.name_win.name_Signal.connect(self._create_AO_shader)
        self.name_win.show()


    def _create_shader(self,shader_name,shader_type):
        shader=cmd.shadingNode(shader_type,name=shader_name, asShader=True)
        return shader


    def _create_aiStandardSurface_shader(self,name):
        """
        create anorld standarsurface shader for the selected obj
        :param name:
        :return:
        """
        obj = cmd.ls(sl=1, dag=1, s=1)
        sd=self._create_shader(name,'aiStandardSurface')
        sg = cmd.sets(renderable=1, empty=1, name=sd+'SG')
        cmd.connectAttr(sd + '.outColor', sg + '.surfaceShader', f=1)
        cmd.select(obj)
        cmd.sets(obj, e=1, forceElement=sg)

    def _create_AO_shader(self,name):
        obj = cmd.ls(sl=1, dag=1, s=1)
        sd=self._create_shader(name,'aiAmbientOcclusion')
        sg = cmd.sets(renderable=1, empty=1, name=sd+'SG')
        cmd.connectAttr(sd + '.outColor', sg + '.surfaceShader', f=1)
        cmd.select(obj)
        cmd.sets(obj, e=1, forceElement=sg)

    ####################################################################################
    #####################           Creat  Shadow          #############################
    ####################################################################################
    def creatShadowGro(self):

        self.shdowlayerGroup = QtWidgets.QGroupBox("Shadow Layer")

        self.shadowLayerbtn = QtWidgets.QPushButton('Create Shadow Layer To Select')
        self.shadowShaderbtn = QtWidgets.QPushButton('Assign ShadowMatte To Select')

        shadowlayerbtnLayout = QtWidgets.QGridLayout()

        shadowlayerbtnLayout.addWidget(self.shadowLayerbtn, 2, 0, 1, 1)
        shadowlayerbtnLayout.addWidget(self.shadowShaderbtn, 2, 1, 1, 1)

        self.shdowlayerGroup.setLayout(shadowlayerbtnLayout)

        self.connect(self.shadowLayerbtn, QtCore.SIGNAL('clicked()'), self.creatShdowLayer)
        self.connect(self.shadowShaderbtn, QtCore.SIGNAL('clicked()'), self.makeShdowShader)

    def creatShdowLayer(self):
        if not self.layerExist('Env_Shdow'):
            cmd.createRenderLayer(name="Env_Shdow", mc=True, nr=True)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.AASamples")
        cmd.setAttr("defaultArnoldRenderOptions.AASamples", 2)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIDiffuseSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISpecularSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GISpecularSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GITransmissionSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GITransmissionSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GISssSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GISssSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.GIVolumeSamples")
        cmd.setAttr("defaultArnoldRenderOptions.GIVolumeSamples", 1)
        cmd.editRenderLayerAdjustment("defaultArnoldRenderOptions.aovMode")
        cmd.setAttr("defaultArnoldRenderOptions.aovMode", 1)
        cmd.editRenderLayerAdjustment("aiAOV_RGBA.lightGroups")
        cmd.setAttr("aiAOV_RGBA.lightGroups", 0)

        sceneAOVs = aovs.AOVInterface().getAOVNodes(names=True)
        for i in sceneAOVs:

            if i[0] != 'OCC':
                cmd.editRenderLayerAdjustment(i[1] + ".enabled")
                cmd.setAttr(i[1] + ".enabled", 0)

            else:
                pass

    def makeShdowShader(self):
        shdow_obj = cmd.ls(sl=True)
        timeaxis_shadow = cmd.createNode('aiShadowMatte', name='timeaxis_shadow')
        cmd.select(shdow_obj)
        cmd.hyperShade(assign=timeaxis_shadow)  # ????????|????????????o??a???1??????????????1??????
        newsdSg = cmd.sets(renderable=1, empty=1, name='sdSG')
        cmd.connectAttr(timeaxis_shadow + '.outColor', newsdSg + '.surfaceShader', f=1)
        cmd.sets(shdow_obj, e=1, forceElement=newsdSg)

    ####################################################################################
    #####################        set SUB               #############################
    ####################################################################################

    def setSubGro(self):

        self.subGroup = QtWidgets.QGroupBox("Ai Batch Set")

        self.subText = QtWidgets.QLabel('Subdivision:')
        self.subTextLine = QtWidgets.QLineEdit('1')
        self.setSub = QtWidgets.QPushButton('Set')
        self.setOpaque = QtWidgets.QPushButton('Opaque')

        subLayout = QtWidgets.QGridLayout()
        subLayout.addWidget(self.subText, 0, 0, 1, 1)
        subLayout.addWidget(self.subTextLine, 0, 1, 1, 1)
        subLayout.addWidget(self.setSub, 0, 2, 1, 1)
        subLayout.addWidget(self.setOpaque, 0, 3, 1, 1)

        self.subGroup.setLayout(subLayout)

        self.connect(self.setSub, QtCore.SIGNAL('clicked()'), self.setSubdFn)
        self.connect(self.setOpaque, QtCore.SIGNAL('clicked()'), self.setopaFn)

    def setSubdFn(self):
        sl = cmd.ls(sl=True, dag=True)
        num = self.subTextLine.text()
        # print num
        for i in sl:
            cmd.setAttr(i + ".aiSubdivType", 1)
            cmd.setAttr(i + ".aiSubdivIterations", int(num))
            # cmd.setAttr (i+".aiOpaque",0)

    def setopaFn(self):
        sl = cmd.ls(sl=True, dag=True)
        for i in sl:
            # cmd.setAttr( i+".aiSubdivType" ,1)
            # cmd.setAttr( i+".aiSubdivIterations" ,int(num))
            cmd.setAttr(i + ".aiOpaque", 0)

    ####################################################################################
    #####################        render window             #############################
    ####################################################################################
    def renderwindowgru(self):

        self.displayRenderWinGro = QtWidgets.QGroupBox("")

        self.disWinbtn = QtWidgets.QPushButton('Repair RenderSetting window')

        displayWinLayout = QtWidgets.QGridLayout()

        displayWinLayout.addWidget(self.disWinbtn, 2, 0, 1, 1)

        self.displayRenderWinGro.setLayout(displayWinLayout)

        self.connect(self.disWinbtn, QtCore.SIGNAL('clicked()'), self.remakeRenderUi)

    def remakeRenderUi(self):
        if cmds.window("unifiedRenderGlobalsWindow", exists=True):
            cmds.deleteUI("unifiedRenderGlobalsWindow")
        mel.eval("unifiedRenderGlobalsWindow;")
        # pm.mel.deleteUI('unifiedRenderGlobalsWindow')
        # pm.mel.buidNewSceneUI()
        # pm.mel.RenderGlobalsWindow()


def getAllLights():
    allLights = []
    if cmd.getAttr("defaultRenderGlobals.currentRenderer") == 'arnold':
        light_node = ['ambientLight', 'directionalLight', 'pointLight', 'spotLight', 'areaLight', 'volumeLight',
                      'aiAreaLight', 'aiSkyDomeLight', 'aiPhotometricLight']
        for node in light_node:
            for ev_light in cmd.ls(type=node):
                allLights.append(ev_light)

    elif cmd.getAttr("defaultRenderGlobals.currentRenderer") == 'redshift':
        light_node = ['ambientLight', 'directionalLight', 'pointLight', 'spotLight', 'areaLight', 'volumeLight',
                      'RedshiftPhysicalLight', 'RedshiftDomeLight']
        for node in light_node:
            for ev_light in cmd.ls(type=node):
                allLights.append(ev_light)
    return allLights
    # light_node = ['ambientLight','directionalLight','pointLight','spotLight','areaLight','volumeLight','aiAreaLight','aiSkyDomeLight','aiPhotometricLight','RedshiftPhysicalLight','RedshiftDomeLight']


def getSelectedLights(*args):
    if cmd.getAttr("defaultRenderGlobals.currentRenderer") == 'arnold':
        selectedLights = cmd.ls(sl=1, type=['ambientLight', 'directionalLight', 'pointLight', 'spotLight', 'areaLight',
                                            'volumeLight', 'aiAreaLight', 'aiSkyDomeLight', 'aiPhotometricLight'],
                                dag=1)
    elif cmd.getAttr("defaultRenderGlobals.currentRenderer") == 'redshift':
        selectedLights = cmd.ls(sl=1, type=['ambientLight', 'directionalLight', 'pointLight', 'spotLight', 'areaLight',
                                            'volumeLight', 'RedshiftPhysicalLight', 'RedshiftDomeLight'], dag=1)
    return selectedLights


def maya_ui():
    dialog = Dialog(parent=maya_main_window())


if __name__ == '__main__':
    maya_ui()